<template>
  <section class="jumbotron">
    <h3 class="jumbotron-heading">Search Github Users</h3>
    <div>
      <input type="text"
             v-model.trim="keyword"
             placeholder="enter the name you search" />&nbsp;<button @click="searchUser">Search</button>
    </div>
  </section>
</template>
<script>
import axios from 'axios'
// 1. axios配置基础路径，超时时间
const request = axios.create({
    baseURL:'https://api.github.com',
    timeout:20000
})
// 2. 响应拦截器，简化数据
request.interceptors.response.use(response=>response.data)

export default {
  name: 'Header',
  data() {
    return {
      keyword: '',
    }
  },
  methods: {
    async searchUser() {
        let {items} = await request.get('/search/users',{
            params:{
                q:this.keyword
            }
        })
        console.log('users : ', items)
        // 发送数据到list组件
        this.$bus.$emit('search-user', items)
    },
  },
}
</script>

<style>
</style>